<template>
  <el-container>
    <el-header style="background-color:#eff2f7" class="top">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/index' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>图表</el-breadcrumb-item>
        <el-breadcrumb-item>用户分布</el-breadcrumb-item>
      </el-breadcrumb>
      <!-- header右侧头像开始 -->
      <div class="block">
        <el-avatar :size="50" :src="circleUrl"></el-avatar>
        <div class="poputs">
          <div @click="tzHome">首页</div>
          <div @click="tzLogin">退出</div>
        </div>
      </div>
      <!-- header右侧头像结束 -->
    </el-header>
    <el-main style="background-color:#ffffff" class="main">
      <!-- 为 ECharts 准备一个具备大小（宽高）的 DOM -->
      <div id="echartsBin" style="width:100%;height: 500px"></div>
    </el-main>
  </el-container>
</template>
<script >
let echarts = require("echarts/lib/echarts");
// 引入饼状图组件
require("echarts/lib/chart/pie");
// 引入提示框和title组件
require("echarts/lib/component/tooltip");
require("echarts/lib/component/title");

export default {
  data() {
    return {
      circleUrl:
        "https://img01.sogoucdn.com/app/a/100520093/fb41c7c77a2454f7-01eba5833e7e38bc-11cc0200d4b834a0dddb28091fd46806.jpg",
    };
  },
  created() {},
  mounted() {
    this.initData();
  },
  methods: {
    tzHome() {
      this.$router.push({ path: "/home" });
    },
    tzLogin() {
      this.$router.push({ path: "/login" });
    },
    //初始化数据
    initData() {
      // 基于准备好的dom，初始化echarts实例
      var myChart = echarts.init(document.getElementById("echartsBin"));
      // 绘制图表
      myChart.setOption({
        title: {
          text: "用户分布",
          left: "center",
        },
        tooltip: {
          trigger: "item",
          formatter: "{a} <br/>{b} : {c} ({d}%)",
        },
        legend: {
          orient: "vertical",
          left: "left",
          data: ["北京", "上海", "深圳", "杭州", "其他"],
        },
        series: [
          {
            name: "访问来源",
            type: "pie",
            radius: "55%",
            center: ["50%", "60%"],
            data: [
              { value: 335, name: "北京" },
              { value: 310, name: "上海" },
              { value: 234, name: "深圳" },
              { value: 135, name: "杭州" },
              { value: 1548, name: "其他" },
            ],
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: "rgba(0, 0, 0, 0.5)",
              },
            },
          },
        ],
      });
    },
  },
};
</script>
<style scoped>
.block {
  position: relative;
}
.poputs {
  position: absolute;
  top: 55px;
  left: -20px;
  width: 80px;
  height: 60px;
  background-color: #fff;
  box-sizing: border-box;
  box-shadow: 2px 3px 10px -1px #333;
  display: none;
  z-index: 999;
}
.poputs > div {
  width: 80px;
  height: 30px;
  line-height: 30px;
  text-align: center;
  color: #000;
  cursor: pointer;
}
.block:hover .poputs {
  display: block;
}
.poputs > div:hover {
  background-color: #e4e8f1;
  color: #333;
}
</style>
